<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Make Controller Kit - Firmware API: Timer</title>
<link href="mt_doxygen.css" rel="stylesheet" type="text/css" />
<link href="../resources/mt_doxytabs.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
.header {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 12pt;
	color: #222222;
}
-->
</style>
</head>

<body>
<table width="800" border="0">
    <tr>
      <td colspan="3">
        <form method="get" action="http://www.google.com/search">
          <div align="right">
            <input type="text"   name="q" size="25"
              maxlength="255" value="" />
            <input type="submit" value="Search" />
            <input type="hidden" name="sitesearch" value="makingthings.com/ref/firmware/html" />
          </div>
        </form>
       </td>
    </tr>
    <tr>
      <td><div align="center"><a href="http://www.makingthings.com">
				<img src="../resources/logo_brown_medium.png" alt="MakingThings"
									width="200" height="78" border="0" align="middle" longdesc="http://www.makingthings.com" /></a></div></td>
				<td><div align="center" class="header">
      		Make Controller Kit <br />
          Firmware API
      </div></td>
      <td><div align="center"><a href="http://www.makezine.com">
					<img src="../resources/make_logo.png" alt="MAKE Zine" 
										width="164" height="73" border="0" align="middle" longdesc="http://www.makezine.com" /></a></div></td>
    </tr>
</table>
</body>
</html>
<!-- Generated by Doxygen 1.5.4 -->
<script type="text/javascript">
<!--
function changeDisplayState (e){
  var num=this.id.replace(/[^[0-9]/g,'');
  var button=this.firstChild;
  var sectionDiv=document.getElementById('dynsection'+num);
  if (sectionDiv.style.display=='none'||sectionDiv.style.display==''){
    sectionDiv.style.display='block';
    button.src='open.gif';
  }else{
    sectionDiv.style.display='none';
    button.src='closed.gif';
  }
}
function initDynSections(){
  var divs=document.getElementsByTagName('div');
  var sectionCounter=1;
  for(var i=0;i<divs.length-1;i++){
    if(divs[i].className=='dynheader'&&divs[i+1].className=='dynsection'){
      var header=divs[i];
      var section=divs[i+1];
      var button=header.firstChild;
      if (button!='IMG'){
        divs[i].insertBefore(document.createTextNode(' '),divs[i].firstChild);
        button=document.createElement('img');
        divs[i].insertBefore(button,divs[i].firstChild);
      }
      header.style.cursor='pointer';
      header.onclick=changeDisplayState;
      header.id='dynheader'+sectionCounter;
      button.src='closed.gif';
      section.id='dynsection'+sectionCounter;
      section.style.display='none';
      section.style.marginLeft='14px';
      sectionCounter++;
    }
  }
}
window.onload = initDynSections;
-->
</script>
<div class="tabs">
  <ul>
    <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
    <li><a href="modules.html"><span>Modules</span></a></li>
    <li><a href="classes.html"><span>Data&nbsp;Structures</span></a></li>
    <li><a href="files.html"><span>Files</span></a></li>
    <li><a href="pages.html"><span>Related&nbsp;Pages</span></a></li>
  </ul>
</div>
<h1>Timer<br>
<small>
[<a class="el" href="group___controller.html">Controller</a>]</small>
</h1>The Timer subsystem provides a timer in a millisecond timeframe.  
<a href="#_details">More...</a><table border="0" cellpadding="0" cellspacing="0">
<tr><td></td></tr>
<tr><td colspan="2"><br><h2>Functions</h2></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">int&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="group___timer.html#g0ba988a1ac434ac70c17dfc239644dfe">Timer_SetActive</a> (bool active)</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Controls the active state of the <b>Timer</b> subsystem.  <a href="#g0ba988a1ac434ac70c17dfc239644dfe"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">int&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="group___timer.html#gbefcf81004fa679f113c0f364d9fca49">Timer_GetActive</a> ()</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Returns whether the timer subsystem is active or not.  <a href="#gbefcf81004fa679f113c0f364d9fca49"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="group___timer.html#g0c6906dbdb6527345121141fb3153744">Timer_InitializeEntry</a> (TimerEntry *timerEntry, void(*timerCallback)(int id), int id, int timeMs, bool repeat)</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Initializes a new timer structure.  <a href="#g0c6906dbdb6527345121141fb3153744"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">int&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="group___timer.html#g7397510285b17f629445eed71855c2c3">Timer_Set</a> (TimerEntry *timerEntry)</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Sets a given TimerEntry to run.  <a href="#g7397510285b17f629445eed71855c2c3"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">int&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="group___timer.html#ge0bc40447f95c2309192ececf1fdee59">Timer_Cancel</a> (TimerEntry *timerEntry)</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Cancel a timer event.  <a href="#ge0bc40447f95c2309192ececf1fdee59"></a><br></td></tr>
</table>
<hr><a name="_details"></a><h2>Detailed Description</h2>
The Timer subsystem provides a timer in a millisecond timeframe. 
<p>
For higher resolution timing, check the <a class="el" href="group___fast_timer.html">Fast Timer</a><p>
The Timer subsystem is based on a collection of <b>TimerEntries</b>. To start a new timer, create a new <b>TimerEntry</b> structure, initialize it with <a class="el" href="group___timer.html#g0c6906dbdb6527345121141fb3153744" title="Initializes a new timer structure.">Timer_InitializeEntry( )</a>, and start it with <a class="el" href="group___timer.html#g7397510285b17f629445eed71855c2c3" title="Sets a given TimerEntry to run.">Timer_Set( )</a>.<p>
There are currently a couple of limitations to the Timer system:<ul>
<li>In your callback function, you must not sleep or make any FreeRTOS-related calls.</li><li>To modify an existing TimerEntry, you must cancel the timer with <a class="el" href="group___timer.html#ge0bc40447f95c2309192ececf1fdee59" title="Cancel a timer event.">Timer_Cancel( )</a>, and reinitialize the TimerEntry.</li></ul>
<p>
<dl compact><dt><b><a class="el" href="todo.html#_todo000007">Todo:</a></b></dt><dd>Allow the timer callbacks to cooperate with the <a class="el" href="group___r_t_o_s.html">RTOS</a> </dd></dl>
<dl compact><dt><b><a class="el" href="todo.html#_todo000007">Todo:</a></b></dt><dd>Allow existing timer entries to be modified (repeat or not, modify the period, etc.) </dd></dl>
<hr><h2>Function Documentation</h2>
<a class="anchor" name="ge0bc40447f95c2309192ececf1fdee59"></a><!-- doxytag: member="timer.c::Timer_Cancel" ref="ge0bc40447f95c2309192ececf1fdee59" args="(TimerEntry *timerEntry)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">int Timer_Cancel           </td>
          <td>(</td>
          <td class="paramtype">TimerEntry *&nbsp;</td>
          <td class="paramname"> <em>timerEntry</em>          </td>
          <td>&nbsp;)&nbsp;</td>
          <td width="100%"></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Cancel a timer event. 
<p>
<dl compact><dt><b>Parameters:</b></dt><dd>
  <table border="0" cellspacing="2" cellpadding="0">
    <tr><td valign="top"></td><td valign="top"><em>timerEntry</em>&nbsp;</td><td>The entry to be removed. </td></tr>
  </table>
</dl>
<dl class="return" compact><dt><b>Returns:</b></dt><dd>0 on success. </dd></dl>
<dl class="see" compact><dt><b>See also:</b></dt><dd><a class="el" href="group___timer.html#g7397510285b17f629445eed71855c2c3" title="Sets a given TimerEntry to run.">Timer_Set</a> </dd></dl>

<p>Definition at line <a class="el" href="timer_8c-source.html#l00218">218</a> of file <a class="el" href="timer_8c-source.html">timer.c</a>.</p>

</div>
</div><p>
<a class="anchor" name="gbefcf81004fa679f113c0f364d9fca49"></a><!-- doxytag: member="timer.c::Timer_GetActive" ref="gbefcf81004fa679f113c0f364d9fca49" args="()" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">int Timer_GetActive           </td>
          <td>(</td>
          <td class="paramtype">void&nbsp;</td>
          <td class="paramname">          </td>
          <td>&nbsp;)&nbsp;</td>
          <td width="100%"></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Returns whether the timer subsystem is active or not. 
<p>
<dl class="return" compact><dt><b>Returns:</b></dt><dd>active. </dd></dl>
<dl class="see" compact><dt><b>See also:</b></dt><dd><a class="el" href="group___timer.html#g7397510285b17f629445eed71855c2c3" title="Sets a given TimerEntry to run.">Timer_Set</a>, <a class="el" href="group___timer.html#ge0bc40447f95c2309192ececf1fdee59" title="Cancel a timer event.">Timer_Cancel</a> </dd></dl>

<p>Definition at line <a class="el" href="timer_8c-source.html#l00097">97</a> of file <a class="el" href="timer_8c-source.html">timer.c</a>.</p>

</div>
</div><p>
<a class="anchor" name="g0c6906dbdb6527345121141fb3153744"></a><!-- doxytag: member="timer.c::Timer_InitializeEntry" ref="g0c6906dbdb6527345121141fb3153744" args="(TimerEntry *timerEntry, void(*timerCallback)(int id), int id, int timeMs, bool repeat)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void Timer_InitializeEntry           </td>
          <td>(</td>
          <td class="paramtype">TimerEntry *&nbsp;</td>
          <td class="paramname"> <em>timerEntry</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">void(*)(int id)&nbsp;</td>
          <td class="paramname"> <em>timerCallback</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int&nbsp;</td>
          <td class="paramname"> <em>id</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int&nbsp;</td>
          <td class="paramname"> <em>timeMs</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">bool&nbsp;</td>
          <td class="paramname"> <em>repeat</em></td><td>&nbsp;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td><td width="100%"></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Initializes a new timer structure. 
<p>
The event is signified by a callback to the function provided, after the interval specified. The specified ID is passed back to the function to permit one function to work for many events. Pass repeat = true to make the event continue to create callbacks until it is canceled. <dl compact><dt><b>Parameters:</b></dt><dd>
  <table border="0" cellspacing="2" cellpadding="0">
    <tr><td valign="top"></td><td valign="top"><em>timerEntry</em>&nbsp;</td><td>pointer to the TimerEntry to be intialized. </td></tr>
    <tr><td valign="top"></td><td valign="top"><em>timerCallback</em>&nbsp;</td><td>pointer to the callback function. The function must be of the form <div class="fragment"><pre class="fragment">void timerCallback( int id )</pre></div> </td></tr>
    <tr><td valign="top"></td><td valign="top"><em>id</em>&nbsp;</td><td>An integer specifying the ID the callback function is to be provided with. </td></tr>
    <tr><td valign="top"></td><td valign="top"><em>timeMs</em>&nbsp;</td><td>The time in milliseconds desired for the callback. </td></tr>
    <tr><td valign="top"></td><td valign="top"><em>repeat</em>&nbsp;</td><td>Set whether the timer repeats or is a one-time event. </td></tr>
  </table>
</dl>
<dl class="see" compact><dt><b>See also:</b></dt><dd><a class="el" href="group___timer.html#ge0bc40447f95c2309192ececf1fdee59" title="Cancel a timer event.">Timer_Cancel</a></dd></dl>
<dl class="user" compact><dt><b>Example</b></dt><dd><div class="fragment"><pre class="fragment">  TimerEntry myTimer; <span class="comment">// our TimerEntry</span>
  <a class="code" href="group___timer.html#g0c6906dbdb6527345121141fb3153744" title="Initializes a new timer structure.">Timer_InitializeEntry</a>( &amp;myTimer, myCallback, 0, 250, <span class="keyword">true</span> );
  <a class="code" href="group___timer.html#g7397510285b17f629445eed71855c2c3" title="Sets a given TimerEntry to run.">Timer_Set</a>( &amp;myTimer ); <span class="comment">// start our timer</span>

  <span class="keywordtype">void</span> myCallback( <span class="keywordtype">int</span> <span class="keywordtype">id</span> ) <span class="comment">// our code that will get called by the timer every 250 ms.</span>
  {
    <span class="comment">// do something here</span>
  }
</pre></div> </dd></dl>

<p>Definition at line <a class="el" href="timer_8c-source.html#l00127">127</a> of file <a class="el" href="timer_8c-source.html">timer.c</a>.</p>

</div>
</div><p>
<a class="anchor" name="g7397510285b17f629445eed71855c2c3"></a><!-- doxytag: member="timer.c::Timer_Set" ref="g7397510285b17f629445eed71855c2c3" args="(TimerEntry *timerEntry)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">int Timer_Set           </td>
          <td>(</td>
          <td class="paramtype">TimerEntry *&nbsp;</td>
          <td class="paramname"> <em>timerEntry</em>          </td>
          <td>&nbsp;)&nbsp;</td>
          <td width="100%"></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Sets a given TimerEntry to run. 
<p>
This routine adds the entry to the running queue and then decides if it needs to start the timer (if it's not running) or alter the timer's clock for a shorter period. <dl compact><dt><b>Parameters:</b></dt><dd>
  <table border="0" cellspacing="2" cellpadding="0">
    <tr><td valign="top"></td><td valign="top"><em>timerEntry</em>&nbsp;</td><td>pointer to the FastTimerEntry to be run. </td></tr>
  </table>
</dl>

<p>Definition at line <a class="el" href="timer_8c-source.html#l00147">147</a> of file <a class="el" href="timer_8c-source.html">timer.c</a>.</p>

</div>
</div><p>
<a class="anchor" name="g0ba988a1ac434ac70c17dfc239644dfe"></a><!-- doxytag: member="timer.c::Timer_SetActive" ref="g0ba988a1ac434ac70c17dfc239644dfe" args="(bool active)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">int Timer_SetActive           </td>
          <td>(</td>
          <td class="paramtype">bool&nbsp;</td>
          <td class="paramname"> <em>active</em>          </td>
          <td>&nbsp;)&nbsp;</td>
          <td width="100%"></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Controls the active state of the <b>Timer</b> subsystem. 
<p>
<dl compact><dt><b>Parameters:</b></dt><dd>
  <table border="0" cellspacing="2" cellpadding="0">
    <tr><td valign="top"></td><td valign="top"><em>active</em>&nbsp;</td><td>whether this subsystem is active or not </td></tr>
  </table>
</dl>
<dl class="return" compact><dt><b>Returns:</b></dt><dd>Zero on success. </dd></dl>
<dl class="see" compact><dt><b>See also:</b></dt><dd><a class="el" href="group___timer.html#g7397510285b17f629445eed71855c2c3" title="Sets a given TimerEntry to run.">Timer_Set</a>, <a class="el" href="group___timer.html#ge0bc40447f95c2309192ececf1fdee59" title="Cancel a timer event.">Timer_Cancel</a> </dd></dl>

<p>Definition at line <a class="el" href="timer_8c-source.html#l00068">68</a> of file <a class="el" href="timer_8c-source.html">timer.c</a>.</p>

</div>
</div><p>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Make Controller Kit</title>
<style type="text/css">
<!--
.footer {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 9pt;
	color: #999999;
}
-->
</style>
</head>

<body>
<hr size="1">
<div>
  <p class="footer">The Make Controller Kit is an open source project maintained by <a href="http://www.makingthings.com">MakingThings</a>.<br />
    MakingThings code is released under the <a href="http://www.apache.org/licenses/LICENSE-2.0.html" target="_blank">Apache 2.0 license</a>.<br />
    Bug tracker, development wiki and status can be found at <a href="http://dev.makingthings.com">http://dev.makingthings.com</a>.<br />
		This document was last updated on 5 Dec 2007.
</p>
</div>
<!-- Google Analytics Code -->
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-769030-1";
urchinTracker();
</script>
</body>
</html>
